package com.siyue.neo4j_demo.controller;

import com.siyue.neo4j_demo.Util.Result;
import com.siyue.neo4j_demo.dao.DongManRepository;
import com.siyue.neo4j_demo.entity.DongMan;
import com.siyue.neo4j_demo.service.DongManService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/dongMan")
@Api(tags="动漫人物操作测试")
public class DongManController {
    @Resource
    DongManService dongManService;

    @Autowired
    DongManRepository dongManRepository;

    @PostMapping("/addDongMan")
    @ApiOperation(value="添加对象节点")
    public Result addDongMan(DongMan dongMan) {
        return Result.success("操作成功！", dongManService.addDongMan(dongMan));
    }

    @PostMapping("/delById")
    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="id",value="主键",paramType="form")
    public Result delById(Long id) {
        dongManService.delById(id);
        return Result.success("操作成功！");
    }

    @PostMapping("/updateDongMane")
    @ApiOperation(value="修改节点信息")
    public Result updateDongMane(DongMan dongMan) {
        return Result.success("操作成功！", dongManService.updateById(dongMan));
    }

    @GetMapping("/getInfoById")
    @ApiOperation(value="根据主键查询")
    @ApiImplicitParam(name="id",value="主键",paramType="form")
    public Result getInfoById(Long id) {
        return Result.success("操作成功！",dongManService.getInfoById(id));
    }

    @GetMapping("/getAllRelationTypes")
    @ApiOperation(value="获取所有的关系类型")
    public Result getAllRelationTypes() {
        return Result.success("操作成功！", dongManService.getAllRealationTypes());
    }

    @PostMapping("/addDMRelationShip")
    @ApiOperation(value="指定两个节点的关系(两个节点须存在)")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="对象名：唐三-",paramType="form"),
            @ApiImplicitParam(name="relation",value="关系[父亲]->",paramType="form"),
            @ApiImplicitParam(name="to",value="对象名：唐昊",paramType = "form")
    })
    public Result addDMRelationShip(String name,String relation,String to) {
        //直接指定关系
        dongManService.createRelation(name, relation, to);
        return Result.success("操作成功！" );
    }

    @GetMapping("/getRelationsByName")
    @ApiOperation(value="获取指定节点指定关系信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="对象名：唐三",paramType="form"),
            @ApiImplicitParam(name="relation",value="具体关系",paramType = "form")
    })
    public Result getRelationsByName(String name,String relation) {
        return Result.success("操作成功！" , dongManService.getRelationsByName(name,relation));
    }


    @GetMapping("/getDongManByName")
    @ApiOperation(value="根据名字获取动漫信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="对象名：唐三",paramType="name"),
    })
    public Result getRelationsByName(String name) {
        return Result.success("操作成功！" , dongManRepository.getDongManByName(name));
    }


    @GetMapping("/getDongManByNameLike")
    @ApiOperation(value="根据名字模糊查询获取动漫信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="对象名：唐三",paramType="name"),
    })
    public Result getRelationsByNameLike(String name) {
        name="~ '.*"+name+".*'";
        System.out.println(name);
        return Result.success("操作成功！" , dongManRepository.getDongManByNameLike(name));
    }

}
